/**
 * 
 */
package wikiextract.nlp.trainingset.x;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.EOFException;
import java.io.IOException;

public class MatchesRecord {
	public int sentenceId;
	public int articleId;
	public int attributesNamesId;
	//public boolean leftSegmentMatch;
	public byte[][] matchPos;
	public byte[] matchLabels;
	public boolean EOF = false;
	
	public boolean read(DataInput di) throws IOException {
		try {
			sentenceId = di.readInt();
			articleId = di.readInt();
			attributesNamesId = di.readInt();
			byte num = di.readByte();
			matchPos = new byte[num][2];
			matchLabels = new byte[num];
			for (int i=0; i < num; i++) {
				matchPos[i][0] = di.readByte();
				matchPos[i][1] = di.readByte();
				matchLabels[i] = di.readByte();
			}
			return true;
		} catch (EOFException e) {
			EOF  = true;
			return false; 
		}
	}
	
	public void write(DataOutput out) throws IOException {
		out.writeInt(sentenceId);
		out.writeInt(articleId);
		out.writeInt(attributesNamesId);
		out.writeByte(matchPos.length);
		for (int i=0; i < matchPos.length; i++) {
			out.writeByte(matchPos[i][0]);
			out.writeByte(matchPos[i][1]);
			out.writeByte(matchLabels[i]);
		}
	}
}